package cn.shengongying.bean;

import cn.shengongying.enums.ResponseCodeEnum;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * author: RXK
 * date: 2022/1/5 星期三
 * desc:
 */
@Getter
@Setter
public class ResponseResult<T> implements Serializable {

    private static final long serialVersionUID = -6877627587556814280L;

    private Integer code;

    private String msg;

    private T data;

    private ResponseResult() {
    }

    private ResponseResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static <T> ResponseResult<T> success(Integer code,String msg,T data) {
        return new ResponseResult<>(code, msg, data);
    }

    public static <T> ResponseResult<T> success(T data) {
        return success(ResponseCodeEnum.success.getCode(), ResponseCodeEnum.success.getMsg(), data);
    }

    public static <T> ResponseResult<T> success() {
        return success(ResponseCodeEnum.success.getCode(), ResponseCodeEnum.success.getMsg(), null);
    }

    public static <T> ResponseResult<T> success(ResponseCodeEnum responseCodeEnum) {
        return success(responseCodeEnum.getCode(), responseCodeEnum.getMsg(), null);
    }

    public static <T> ResponseResult<T> fail(ResponseCodeEnum responseCodeEnum) {
        return success(responseCodeEnum.getCode(), responseCodeEnum.getMsg(), null);
    }

    public static <T> ResponseResult<T> fail() {
        return success(ResponseCodeEnum.fail.getCode(), ResponseCodeEnum.fail.getMsg(), null);
    }

    public static <T> ResponseResult<T> fail(Integer code,String msg) {
        return success(code, msg, null);
    }

}
